import { MessageBox } from "element-ui";

/**
 * GET URL拼接
 */
export function toGet(url, params) {
  let searchStr = "?";
  for (let val in params) {
    if (params[val] && params[val] != null) {
      searchStr += val + "=" + params[val] + "&";
    }
  }
  if (searchStr[searchStr.length - 1] === "&") {
    searchStr = searchStr.slice(0, searchStr.length - 1);
  }
  return url + searchStr;
}

/**
 * 弹出框提示消息
 * success/warning/info/error
 */
export function resMessage(title, msg, type) {
  MessageBox.alert(msg, "提示", {
    title: title,
    confirmButtonText: "确定",
    type: type,
  });
}

/**
 * 数组对象转一维数组
 */
export function toArrar(list, field) {
  let params = [];
  list.forEach((v) => {
    params.push(v[field]);
  });
  return params;
}
